﻿using UnityEngine;
using System.Collections;
/// <summary>
/// 柱子的移动
/// </summary>
public class zhuzi : MonoBehaviour
{
    public float speed = 1;
    // Use this for initialization
    void Start()
    {
        //随机出位置
        //-1.139981 3.551059;
        myTran.position = new Vector3(3.6f, Random.Range(-1.139981f, 3.551059f));
        GameCtrl.restHandler += cls;
    }
    Transform myTran;
    void Awake()
    {
        myTran = transform;
    }
    bool added = false;
    void Update()
    {
        if(GameCtrl.gameState == GameState.gameing)
        {
            myTran.Translate(Vector3.left * speed * Time.deltaTime);

            if(myTran.position.x <= -3.8f)
            {
                GameCtrl.restHandler -= cls;
                cls();
            }

            if(myTran.position.x <= -1.08f && !added)
            {
                added = true;
                GameCtrl.Inst.addScore();
            }
        }
    }
    void cls()
    {
        if(this != null)
            Destroy(gameObject);
    }

}
